package client.service.impl;

import client.config.URLConfig;
import client.mapper.HelloTestMapper;
import client.service.IHelloTestService;
import client.until.RestTemplateUtils;
import com.alibaba.fastjson.JSONObject;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author chengyadong
 * @date 2023/11/28 15:11
 * @description
 */
@Service
public class HelloTestServiceImpl implements IHelloTestService {
	@Autowired
	HelloTestMapper helloTestMapper;
	@Autowired
	RestTemplateUtils restTemplateUtils;

	@Value("${resources-project.url}")
	private String resourcesProjectUrl;
	@Value("${resources-project.name}")
	private String resourcesProjectName;

	@Autowired
	URLConfig urlConfig;

	@Override
	public Map query() {
		return helloTestMapper.query();
	}

	@Override
	public Map queryByResource(HttpServletRequest request) {
		String url = resourcesProjectUrl + resourcesProjectName + urlConfig.queryByResource();
		//获取token值
		String token = restTemplateUtils.getAccessToken(request);
		final JSONObject jsonObject = restTemplateUtils.httpPostRequestForEntity(url, "", token);
		return jsonObject;
	}

	@Override
	public Map update() {
		return helloTestMapper.update();
	}
}
